(setq user-full-name "pzy")
(setq user-mail-address "husthecor@gmail.com")

;;;;;;;;;;;;;; 设置字体 ;;;;;;;;;;;;;;;;
;;(set-default-font "Courier 10 Pitch:style=Regular:size=14")
;;(set-fontset-font "fontset-default" 'gb18030 '("Microsoft YaHei" . "unicode-bmp")) 
(setq w32-charset-info-alist
    (cons '("gbk" w32-charset-gb2312 . 936) w32-charset-info-alist))

(setq default-frame-alist
      (append
       '((font . "fontset-gbk")) default-frame-alist))

(create-fontset-from-fontset-spec
  "-outline-Courier New-normal-r-normal-normal-16-97-96-96-c-*-fontset-gbk")
(set-fontset-font
 "fontset-default" nil
 "-outline-新宋体-normal-r-normal-*-14-*-96-96-c-*-iso10646-1" nil 'prepend)
(set-fontset-font
 "fontset-gbk" 'kana
 "-outline-新宋体-normal-r-normal-*-18-*-96-96-c-*-iso10646-1" nil 'prepend)
(set-fontset-font
 "fontset-gbk" 'han
 "-outline-新宋体-normal-r-normal-*-14-*-96-96-c-*-iso10646-1" nil 'prepend)
(set-fontset-font
 "fontset-gbk" 'cjk-misc
 "-outline-新宋体-normal-r-normal-*-14-*-96-96-c-*-iso10646-1" nil 'prepend)
(set-fontset-font
 "fontset-gbk" 'symbol
 "-outline-新宋体-normal-r-normal-*-14-*-96-96-c-*-iso10646-1" nil 'prepend)
(set-default-font "fontset-gbk")

(setq default-tab-width 4)
;;;;退出Emacs时保存所有正在编辑的文档
(load "desktop")
(desktop-save-mode)
(desktop-read)

(custom-set-variables)
(custom-set-faces
 '(tooltip ((((class color)) (:inherit variable-pitch :background "lightyellow" :foreground "black" :family "Courier 10 Pitch")))))
(tool-bar-mode -1)
(scroll-bar-mode nil)
(menu-bar-mode 1)
(setq visible-bell t)
(setq inhibit-startup-message t)
(setq column-number-mode t)
(require 'session)
(add-hook 'after-init-hook 'session-initialize)

;; (require 'tabbar)
;; (tabbar-mode 1)
;; (dolist (func '(tabbar-mode tabbar-forward-tab tabbar-forward-group tabbar-backward-tab tabbar-backward-group))
;;   (autoload func "tabbar" "Tabs at the top of buffers and easy control-tab navigation"))
;; (defmacro defun-prefix-alt (name on-no-prefix on-prefix &optional do-always)
;;   `(defun ,name (arg)
;;      (interactive "P")
;;      ,do-always
;;      (if (equal nil arg)
;;          ,on-no-prefix
;;        ,on-prefix)))
;; (defun-prefix-alt shk-tabbar-next (tabbar-forward-tab) (tabbar-forward-group) (tabbar-mode 1))
;; (defun-prefix-alt shk-tabbar-prev (tabbar-backward-tab) (tabbar-backward-group) (tabbar-mode 1))
;; (global-set-key [(control tab)] 'shk-tabbar-next)
;; (global-set-key [(control shift tab)] 'shk-tabbar-prev)
;;  (defun tabbar-buffer-groups ()
;;    "Return the list of group names the current buffer belongs to.
;;  This function is a custom function for tabbar-mode's tabbar-buffer-groups.
;;  This function group all buffers into 3 groups:
;;  Those Dired, those user buffer, and those emacs buffer.
;;  Emacs buffer are those starting with “*”."
;;    (list
;;     (cond
;;      ((string-equal "*" (substring (buffer-name) 0 1))
;;       "Emacs Buffer"
;;       )
;;      ((eq major-mode 'dired-mode)
;;       "Dired"
;;       )
;;      (t
;;       "User Buffer"
;;       )
;;      ))) ;; from Xah Lee

;; (setq tabbar-buffer-groups-function 'tabbar-buffer-groups)

(require 'color-theme)
(color-theme-dark-blue)
(setq frame-title-format "emacs@%b")
(setq display-time-24hr-format t)
(display-time-mode t)
;(setq display-time-day-and-date t) 
(transient-mark-mode t)
(setq mouse-yank-at-point t)
;(setq kill-ring-max 200)
(setq default-fill-column 80)
;(setq scroll-margin 3
;      scroll-conservatively 10000)
(setq default-major-mode 'text-mode)
(show-paren-mode t)
(setq show-paren-style 'parentheses)
(mouse-avoidance-mode 'animate)
(auto-image-file-mode)
(global-font-lock-mode t)
(fset 'yes-or-no-p 'y-or-n-p)
(add-to-list 'backup-directory-alist '("." . "~/.emacs_backupdir"))
(require 'bm)
(require 'bm-ext)
(global-set-key [C-f3] 'bm-toggle)
(global-set-key [f3] 'bm-next)
(global-set-key [S-f3] 'bm-previous)
(require 'ido)
(ido-mode t)
;; (setq ido-execute-command-cache nil)
;; (defun ido-execute-command ()
;;    (interactive)
;;    (call-interactively
;;     (intern
;;      (ido-completing-read
;;       "M-x "
;;       (progn
;;         (unless ido-execute-command-cache
;;           (mapatoms (lambda (s)
;;                       (when (commandp s)
;;                         (setq ido-execute-command-cache
;;                               (cons (format "%S" s) ido-execute-command-cache))))))
;;         ido-execute-command-cache)))))
    
;;  (add-hook 'ido-setup-hook
;;            (lambda ()
;;              (setq ido-enable-flex-matching t)
;;              (global-set-key "\M-x" 'ido-execute-command)))
(defun z-ido-execute-command ()
   (interactive)
   (call-interactively
    (intern
     (ido-completing-read
      "command: "
      (list "menu-bar-mode" "eshell" "open-eshell-other-buffer" "ipython" "compile" "next-error" "mark-defun" "replace-string" "replace-regexp" "outline-toggle-children" "bm-toggle" "bm-next" "bm-previous" "bm-all" "fullscreen")))))

(global-set-key "\M-z" 'z-ido-execute-command)
;; (require 'template)
(require 'maximize)
(add-hook 'window-setup-hook 'maximize-frame t)

;(require 'session)
;(add-hook 'after-init-hook 'session-initialize)
;(desktop-save-mode 1)

;; (setq outline-minor-mode-prefix [(control j)])
(outline-minor-mode 1)

(defadvice kill-ring-save (before slickcopy activate compile)
  "When called interactively with no active region, copy a single line instead."
  (interactive
   (if mark-active (list (region-beginning) (region-end))
     (list (line-beginning-position)
   (line-beginning-position 2)))))

(defadvice kill-region (before slickcut activate compile)
  "When called interactively with no active region, kill a single line instead."
  (interactive
   (if mark-active (list (region-beginning) (region-end))
     (list (line-beginning-position)
   (line-beginning-position 2)))))

(defun vi-open-next-line (arg)
 "Move to the next line (like vi) and then opens a line."
 (interactive "p")
 (end-of-line)
 (open-line arg)
 (next-line 1)
 (indent-according-to-mode))
(global-set-key [(control o)] 'vi-open-next-line)

;; Always end searches at the beginning of the matching expression.
(add-hook 'isearch-mode-end-hook 'goto-match-beginning)
(defun goto-match-beginning ()
  "Use with isearch hook to end search at first char of match."
    (when isearch-forward (goto-char isearch-other-end)))
(global-set-key [(control r)] 'isearch-backward-regexp)
(global-set-key [(control s)] 'isearch-forward-regexp)

(setq-default kill-whole-line t)


(defadvice save-buffers-kill-emacs (around no-query-kill-emacs activate)
        "Prevent annoying \"Active processes exist\" query when you quit Emacs."
        (flet ((process-list ())) ad-do-it))

(global-set-key "\C-m" 'newline-and-indent)
(global-set-key [f2] 'replace-string)
(global-set-key [S-f2] 'replace-regexp)
(server-start)
(global-set-key [f9] 'rename-buffer)


(add-to-list 'load-path "~/.emacs.d/yasnippet")
(require 'yasnippet)
(yas/initialize)
(yas/load-directory "~/.emacs.d/yasnippet/snippets")
(require 'init-auto-complete)
(abbrev-mode 1)
(setq default-abbrev-mode t)
(setq save-abbrevs t)
(setq abbrev-file-name "~/.emacs.d/abbrev_defs")
(quietly-read-abbrev-file)
(setq-default ispell-program-name "aspell")
(setq-default ispell-extra-args '("--reverse"))
(setq ispell-personal-dictionary "~/.emacs.d/personal-dictionary")
(setq ispell-silently-savep t)
(setq ispell-dictionary "english")
(setq ispell-complete-word-dict (expand-file-name "~/.emacs.d/words"))

(global-set-key (kbd "M-1") 'delete-other-windows)
(global-set-key (kbd "M-2") 'split-window-vertically)
(global-set-key (kbd "M-3") 'split-window-horizontally)
(global-set-key (kbd "M-`") 'other-window)

(require 'sr-speedbar)
(global-set-key (kbd "<f5>") 'sr-speedbar-toggle)

;; (require 'filladapt)
;; (setq-default filladapt-mode t)

(require 'browse-kill-ring)
(global-set-key [(control c)(k)] 'browse-kill-ring)
(browse-kill-ring-default-keybindings)
 (add-hook 'term-mode-hook
 		  (function
 		   (lambda ()
 			 (setq term-prompt-regexp "^[^#$%>\n]*[#$%>] *")
 			 (make-local-variable 'mouse-yank-at-point)
 			 (make-local-variable 'transient-mark-mode)
 			 (setq mouse-yank-at-point t)
 			 (setq transient-mark-mode nil)
 			 (auto-fill-mode -1)
 			 (setq tab-width 8 ))))

(provide 'general)
